var app = getApp();

Page({
  data: {
    loadMore: false,
    jionData:[],
    page : 1,
    hadList:true
  },
  
  onLoad: function (options) {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    });
    wx.request({
      url: app.globalData.phpUrl + 'user/api',
      method: 'POST',
      data: { api_name: 'answer_log', openid: options.openOId, page: that.data.page, psize:11},
      success: function (e) {
        wx.hideLoading();
        that.setData({
          jionData: that.data.jionData.concat(e.data.data.list),
          openOId: options.openOId,
          page: that.data.page + 1
        });
      }
    })
  },

  continue1: function(e){
    var dataSet = e.currentTarget.dataset;
    var cover = dataSet.cover || '没有图片!';
    var title = dataSet.title;
    var money = dataSet.money;
    var id = dataSet.id;
    var continue1 = Number(dataSet.continue);
    var question_count = dataSet.question_count;

    wx.navigateTo({
      url: '../../reply/reply?cover=' + cover + '&title=' + title + '&total_money=' + money + '&id=' + id + '&question_num=' + continue1 + '&opid=' + app.globalData.userData.openOId + '&question_count=' + question_count,
    })
  },

  onShareAppMessage: function (e) {
    var id = e.target.dataset.id;
    var serName = '您的朋友';
    if(app.globalData.userInfo.nickName){
      serName = app.globalData.userInfo.nickName
    }
    return {
      title: serName+'邀请你来答题抢红包!',
      imageUrl: '../../../images/shareImg.png',
      path: 'pages/reply/reply?id=' + id + '&article=true',
    }
  },

  // 上拉加载更多
  onReachBottom: function () {
    var that = this;
    
    if (that.data.hadList == false){
           console.log('加载完...')
           return
    }

    that.setData({
      loadMore:true
    });
    
    wx.request({
      url: app.globalData.phpUrl + 'user/api',
      method: 'POST',
      data: { api_name: 'answer_log', openid: that.data.openOId, page: that.data.page, psize: 11 },
      success: function (e) {
        wx.hideLoading();
        if (e.data.data.list.length == 0){
          that.setData({
            hadList:false
          })
        };
        that.setData({
          jionData: that.data.jionData.concat(e.data.data.list),
          loadMore: false,
          page: that.data.page + 1
        });
      }
    });

  }


})